package com.cloudptt.wp.ui.address.workspace;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudptt.api.product.func.crsc.FuncNumOb;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.mcptt.db.model.UserInfo;

import java.util.List;

class LoginFuncObAdapter extends BaseAdapter {
    private Context ctx = null;
    private int selectedPos = 0;
    private List<FuncNumOb> funcNumObList = null;
    public LoginFuncObAdapter(Context ctx,List<FuncNumOb> funcNumObList)
    {
        this.ctx = ctx;
        this.funcNumObList = funcNumObList;
    }
    public void setFuncNumObList(List<FuncNumOb> funcNumObList) {
        this.funcNumObList = funcNumObList;
    }
    public void setSelectedPos(int position) {
        selectedPos = position;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(funcNumObList ==null)
        {
            return 0;
        }
        return funcNumObList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return funcNumObList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder viewHolder = new ViewHolder();

        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(ctx);
            convertView = inflater.inflate(R.layout.func_login_layout, parent, false);
            viewHolder.title = (TextView)convertView.findViewById(R.id.funcTv);
            viewHolder.selectIv = (ImageView)convertView.findViewById(R.id.selectIv);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Log.debug(this.getClass(),"getView position = " + position + " funcNumObList.size = " + funcNumObList.size());
        final FuncNumOb ob = funcNumObList.get(position);
        viewHolder.title.setText(ob.getFuncNumDesc());

        if (selectedPos == position) {
            viewHolder.selectIv.setVisibility(View.VISIBLE);
        } else {
            viewHolder.selectIv.setVisibility(View.GONE);
        }
        return convertView;
    }

    final class ViewHolder{

        public TextView title;
        public ImageView selectIv;

    }
}

